package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsTopicMapper;
import com.qf.pojo.DtsTopic;
import com.qf.service.DtsTopicService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Cc
 * @version 1.0
 */
@Service
public class DtsTopicServiceImpl implements DtsTopicService {

    @Autowired
    private DtsTopicMapper  dtsTopicMapper;

    @Override
    public IPage<DtsTopic> page( Integer page, Integer limit, String sort, String order) {
        Page<DtsTopic> storagePage = new Page<>(page, limit);
        QueryWrapper<DtsTopic> wrapper = new QueryWrapper<>();
        wrapper.orderBy(!StringUtils.isEmpty(sort) , !order.equals("desc"), sort )
                .eq("deleted",false);
        Page<DtsTopic> resultPage = dtsTopicMapper.selectPage(storagePage, wrapper);
        return resultPage;
    }

    @Override
    public void addTopic(DtsTopic topic) {
        dtsTopicMapper.insert(topic);
    }

    @Override
    public void updateTopic(DtsTopic topic) {
        dtsTopicMapper.updateById(topic);
    }

    @Override
    public void deleteTopic(Integer id) {
        dtsTopicMapper.deleteUpdateById(id);
    }


}
